package com.happy_hao.user.controller;

import com.happy_hao.user.common.Result;
import com.happy_hao.user.dto.CreateUserRequest;
import com.happy_hao.user.dto.UpdateUserRequest;
import com.happy_hao.user.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/create")
    public Result createUser(@RequestBody CreateUserRequest createUserRequest) {
        return userService.createUser(createUserRequest);
    }

    @GetMapping("/readById")
    public Result readUserById(@RequestParam("id") Long id) {
        return userService.readUserById(id);
    }

    @GetMapping("/readByIdentifier")
    public Result readUserByName(@RequestParam("identifier") String identifier) {
        return userService.readUserByIdentifier(identifier);
    }

    @RequestMapping("/update")
    public Result updateUser(@RequestBody UpdateUserRequest updateUserRequest) {
        return userService.updateUser(updateUserRequest);
    }

    @DeleteMapping("/delete")
    public Result deleteUser(@RequestParam("id") Long id) {
        return userService.deleteUser(id);
    }

}
